namespace SB2.Core
{
    public class PagedRequest : PageModel
    {

        public List<SeachRequest> Params { get; set; }
        public List<IConditionalModel> GetConditions()
        {

            var res = new List<IConditionalModel>();
            if (Params != null)
            {
                Params.ForEach(m =>
                {
                    res.Add(m.GetConditionalModel());
                });
            }
            return res;
        }
        public string GetOrder()
        {
            return string.Empty;
        }
    }
    public class SeachRequest
    {
        /// <summary>
        /// 列名
        /// </summary>
        /// <value></value>
        public string ColumnName { get; set; }
        /// <summary>
        /// 实际 字段名称
        /// </summary>
        /// <value></value>
        public string FieldName { get; set; }
        /// <summary>
        /// 值
        /// </summary>
        /// <value></value>
        public object Value { get; set; }
        /// <summary>
        /// 数据类型
        /// </summary>
        /// <value></value>
        public DisplayDtoDataType DataType { get; set; }
        public IConditionalModel GetConditionalModel()
        {

            switch (this.DataType)
            {
                case DisplayDtoDataType.Enums:
                    return GetEqualConditionalModel();
                case DisplayDtoDataType.Text:
                    return GetLikeConditionalModel();
                default:
                    return GetEqualConditionalModel();

            }
        }
        IConditionalModel GetEqualConditionalModel()
        {
            return new ConditionalModel
            {
                FieldName = FieldName,
                FieldValue = Value + "",
                ConditionalType = ConditionalType.Equal
            };
        }
        IConditionalModel GetLikeConditionalModel()
        {
            return new ConditionalModel
            {
                FieldName = FieldName,
                FieldValue = Value + "",
                ConditionalType = ConditionalType.Like
            };
        }
    }
}